﻿using Colorful.Control;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Colorful.Control.Services;
using Colorful.Test.Mock;
using System.Windows.Input;
using System.Threading;

namespace Colorful.Test.Unit
{       
    [TestClass]
    public class ColorfulViewModelTest
    {       
        [TestMethod]
        public void ItemsPerPageTest()
        {
            IGetColors colorService = new NullColorServiceMock();
            ColorfulViewModel target = new ColorfulViewModel(colorService);
            int expected = 15;
            int actual = target.ItemsPerPage;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CurrentPageIndex
        ///</summary>
        [TestMethod]
        public void CurrentPageIndexTest()
        {
            IGetColors colorService = new NullColorServiceMock();
            ColorfulViewModel target = new ColorfulViewModel(colorService); 
            int expected = 0;
            int actual = target.CurrentPageIndex;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Search
        ///</summary>
        [TestMethod]
        public void SearchTest()
        {           
            IGetColors colorService = new DesignTimeColorServiceStub();
            ColorfulViewModel target = new ColorfulViewModel(colorService);
            target.ExecuteSearchCommand.Execute(null);
        }    

        /// <summary>
        ///A test for PreviousPage
        ///</summary>
        [TestMethod]
        public void PreviousPageTest()
        {
            IGetColors colorService = new DesignTimeColorServiceStub();
            ColorfulViewModel target = new ColorfulViewModel(colorService);
            target.PreviousPageCommand.Execute(null);
        }

        /// <summary>
        ///A test for NextPage
        ///</summary>
        [TestMethod]
        public void NextPageTest()
        {
            IGetColors colorService = new DesignTimeColorServiceStub();
            ColorfulViewModel target = new ColorfulViewModel(colorService);
            target.NextPageCommand.Execute(null);
        }

        /// <summary>
        ///A test for ColerfulPresentationModel Constructor
        ///</summary>
        [TestMethod]
        public void ColorfulPresentationModelConstructorTest()
        {
            IGetColors colorService = new NullColorServiceMock();
            ColorfulViewModel target = new ColorfulViewModel(colorService);
            
            Assert.IsNotNull(target);
            Assert.IsNotNull(target.Palettes);
            Assert.AreEqual<ColorList>(ColorList.Recent, target.CurrentList);
        }

        /// <summary>
        ///A test for ColorfulPresentationModel Constructor
        ///</summary>
        [TestMethod]
        public void EmptyColorfulPresentationModelConstructorTest()
        {
            ColorfulViewModel target = new ColorfulViewModel();
            Assert.IsNotNull(target);
            Assert.IsNotNull(target.Palettes);
            Assert.AreEqual<ColorList>(ColorList.Recent, target.CurrentList);
        }

        /// <summary>
        /// Test that the ColorfulPresentationModel behaves correctly
        /// when an exception occur while getting colors.
        /// </summary>
        [TestMethod]
        public void ExceptionGetColorsTest()
        {
            ColorfulViewModel target = new ColorfulViewModel(new ExceptionColorServiceMock());
            target.ExecuteSearchCommand.Execute(null);
        }
    }
}